/**
 * 
 * 结果页
 *
 */
class ResultView extends BaseEuiView {
    public resultImg: eui.Image;
    public reserveView: eui.Button;
    public retryView: eui.Button;
    public shareView: eui.Button;

    private static hualun = "result_hualun_png";
    private static meihuan = "result_meihuan_png";
    private static wanmei = "result_wanmei_png";
    private static xiaowanzi = "result_xiaowanzi_png";
    private static xiaoyu = "result_xiaoyu_png";
    public constructor() {
        super();
    }
    
    
    /**  emxl路径 */
    protected exml(): string {
        return "ResultSkin";
    }
    
    /** 初始化设置UI */
    protected initUI(): void {
        this.left = this.right = this.bottom = this.top = 0;
        this.showResult();
        this.reserveView.addEventListener(egret.TouchEvent.TOUCH_TAP,this.clickReserve,this);
        this.retryView.addEventListener(egret.TouchEvent.TOUCH_TAP,this.clickRetry,this);
        this.shareView.addEventListener(egret.TouchEvent.TOUCH_TAP,this.clickShare,this);
    }
    
    public showResult(){
        var result = AppData.get.isWhatRole();
        switch(result) {
            case 1:
                this.resultImg.source = ResultView.xiaoyu;
                break;
            case 2:
                this.resultImg.source = ResultView.hualun;
                break;
            case 3:
                this.resultImg.source = ResultView.wanmei;
                break;
            case 4:
                this.resultImg.source = ResultView.xiaowanzi;
                break;
            case 5:
                this.resultImg.source = ResultView.meihuan;
                break;
            default:
                this.resultImg.source = ResultView.xiaowanzi;
                break;
        }
    }
    
    /** 预约 */
    private clickReserve(): void {
        this.openNextQuestion(1);
    }

    /** 重玩 */
    private clickRetry(): void {
        AppData.get.reset();
        this.openNextQuestion(2);
        
    }
    /** 分享 */
    private clickShare(): void {
        this.openNextQuestion(3);
    }
    /**
     * type=1 预约，2重玩，3分享
     */ 
    private openNextQuestion(type:number) {
        this.dispatchEventWith(CMDEvent.RESUlT_OPERATE,false,type);
    }
    
}
